package com.contory.ssn_lgnd.app.maingame;

import java.util.LinkedList;

import android.util.Log;

import com.contory.ssn_lgnd.app.Assets;
import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;
import com.contory.ssn_lgnd.framework.math.Polygon;
import com.contory.ssn_lgnd.framework.math.Vector2;

public class EventNotifier implements ColiObjPtr, DrawPtr, UpdatePtr{
	Polygon coliBound;
	public static final int ID = 4000;
	ViewObject view;
	byte state = 0;
	final ColisionManager cm;
	EventManager em;
	
	public EventNotifier(float x, float y, float w, float h, ColisionManager cm){
		view = new ViewObject();
		view.setXY_WH_TR(x, y, w, h, Assets.tex_reg_whiteTexel);
		view.setRGBA(1, 0, 0, 1);
		
		coliBound = new Polygon();
		coliBound.lockAddPoint(w, h);
		coliBound.addPoint(0, 0);
		coliBound.addPoint(1, 0);
		coliBound.addPoint(1, 1);
		coliBound.addPoint(0, 1);
		coliBound.unLockAddPoint();
		coliBound.setPos(x, y);
		
		this.cm = cm;
		cm.addEventObj(this);
		em = new EventManager();
	}
	
	public void addEventGroup(){
		em.addEventGroup();
	}
	
	public void addEvent(EventObjectPtr eventObj){
		em.addEvent(eventObj);
	}
	
	@Override
	public Polygon getColiBound() {
		return coliBound;
	}

	@Override
	public float getPosX() {
		return view.x;
	}

	@Override
	public float getPosY() {
		return view.y;
	}

	@Override
	public int getID() {
		return ID;
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		batcher.drawSprite(view.x, view.y, view.w, view.h, view.r, view.g, view.b, view.a, view.tr);
	}
	
	public void excute(){
		state = 1;
		em.excute();
	}
	
	public boolean getEndBool(){
		if(state == 3){
			return true;
		}
		return false;
	}

	@Override
	public void update(float deltaTime) {
		switch(state){
			case 0:
			break;
			
			case 1:
				cm.removeEventObj(this);
				state = 2;
			break;
			
			case 2:
				em.update(deltaTime);
				if(em.getEndBool())
					state = 3;
			break;
			
			case 3:
			break;
		}
	}

	@Override
	public boolean getEnableBool() {
		//STUB
		return false;
	}

	@Override
	public void setEnable(boolean enalbeBool) {
		//STUB
	}

	@Override
	public void setEnergy(int energy) {
		//STUB
	}

	@Override
	public int getEnergy() {
		//STUB
		return 0;
	}
}
